package appconfig

import (
	"fmt"

	"github.com/spf13/viper"
)

type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}
type Redis struct {
	Host     string
	Port     int
	Password string
	Database int
}
type AppConfig struct {
	Mysql
	Redis
}

var Config AppConfig

func Init() {
	var err error
	viper.SetConfigFile("../appconfig/config.yaml")
	err = viper.ReadInConfig()
	if err != nil {
		panic("配置读取失败")
	}
	err = viper.Unmarshal(&Config)
	if err != nil {
		panic("配置解析失败")
	}
	fmt.Println("配置动态读取成功", Config)
}
